package com.work.work_demo.work8;

import java.util.ArrayList;
import java.util.Collections;
import java.util.HashSet;
import java.util.Random;

public class Test1 {
    public static void main(String[] args) {
        // 1.创建Random随机数对象
        Random random = new Random();
        //2.创建HashSet用于保存不重复的红球
        HashSet<Integer> integers = new HashSet<>();
        //3.循环判断红球数量是否小于6个
        while (integers.size() < 6) {
            //4.球数量小于6个就产生一个红球.添加到HashSet中
            //5.如果产生重复号码，往HashSet里添加不进去，所以会再次生成号码
            int i = random.nextInt(33) + 1;
            integers.add(i);
        }
        //6.创建ArrayList集合
        ArrayList<Integer> integers1 = new ArrayList<>();
        for (Integer integer : integers) {
            integers1.add(integer);
        }
        //7.排序
        Collections.sort(integers1);
        //8.再生成一个蓝球
        int it = random.nextInt(16) + 1;
        //9.打印中奖号码
        System.out.println("双色球中奖号码");
        System.out.println("红色是");
        for (Integer redBall : integers) {
            System.out.print(redBall + " ");
        }
        System.out.println();
        System.out.println("篮球是" + it);
    }
}